from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-21 14:10:54.655435
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 21, Apr, 2021
Time: 14:10:59
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6656
Nobs: 268.000 HQIC: -48.3872
Log likelihood: 3216.31 FPE: 5.96349e-22
AIC: -48.8715 Det(Omega_mle): 4.28855e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.430801 0.122984 3.503 0.000
L1.Burgenland 0.084505 0.060955 1.386 0.166
L1.Kärnten -0.220992 0.053604 -4.123 0.000
L1.Niederösterreich 0.093761 0.131418 0.713 0.476
L1.Oberösterreich 0.216758 0.125709 1.724 0.085
L1.Salzburg 0.266022 0.069586 3.823 0.000
L1.Steiermark 0.114220 0.088580 1.289 0.197
L1.Tirol 0.117027 0.060957 1.920 0.055
L1.Vorarlberg -0.034227 0.056196 -0.609 0.542
L1.Wien -0.058058 0.113836 -0.510 0.610
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.476150 0.143071 3.328 0.001
L1.Burgenland 0.004566 0.070911 0.064 0.949
L1.Kärnten 0.328767 0.062359 5.272 0.000
L1.Niederösterreich 0.078947 0.152883 0.516 0.606
L1.Oberösterreich -0.059195 0.146241 -0.405 0.686
L1.Salzburg 0.219070 0.080951 2.706 0.007
L1.Steiermark 0.100517 0.103048 0.975 0.329
L1.Tirol 0.138691 0.070913 1.956 0.050
L1.Vorarlberg 0.156157 0.065374 2.389 0.017
L1.Wien -0.432172 0.132429 -3.263 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.278883 0.062356 4.472 0.000
L1.Burgenland 0.097417 0.030906 3.152 0.002
L1.Kärnten -0.016404 0.027179 -0.604 0.546
L1.Niederösterreich 0.075055 0.066633 1.126 0.260
L1.Oberösterreich 0.286182 0.063738 4.490 0.000
L1.Salzburg 0.020157 0.035282 0.571 0.568
L1.Steiermark -0.005087 0.044913 -0.113 0.910
L1.Tirol 0.070582 0.030907 2.284 0.022
L1.Vorarlberg 0.082318 0.028493 2.889 0.004
L1.Wien 0.114174 0.057718 1.978 0.048
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.216795 0.059822 3.624 0.000
L1.Burgenland 0.023307 0.029650 0.786 0.432
L1.Kärnten 0.008812 0.026074 0.338 0.735
L1.Niederösterreich 0.053514 0.063924 0.837 0.403
L1.Oberösterreich 0.400878 0.061147 6.556 0.000
L1.Salzburg 0.082053 0.033848 2.424 0.015
L1.Steiermark 0.127084 0.043087 2.949 0.003
L1.Tirol 0.050209 0.029651 1.693 0.090
L1.Vorarlberg 0.083362 0.027335 3.050 0.002
L1.Wien -0.046019 0.055372 -0.831 0.406
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.495397 0.117077 4.231 0.000
L1.Burgenland 0.094079 0.058027 1.621 0.105
L1.Kärnten 0.009909 0.051030 0.194 0.846
L1.Niederösterreich 0.000442 0.125106 0.004 0.997
L1.Oberösterreich 0.134453 0.119671 1.124 0.261
L1.Salzburg 0.059771 0.066244 0.902 0.367
L1.Steiermark 0.059874 0.084326 0.710 0.478
L1.Tirol 0.210745 0.058030 3.632 0.000
L1.Vorarlberg 0.034480 0.053497 0.645 0.519
L1.Wien -0.091745 0.108369 -0.847 0.397
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193095 0.092789 2.081 0.037
L1.Burgenland -0.010763 0.045989 -0.234 0.815
L1.Kärnten -0.007482 0.040443 -0.185 0.853
L1.Niederösterreich -0.000014 0.099153 -0.000 1.000
L1.Oberösterreich 0.412714 0.094845 4.351 0.000
L1.Salzburg 0.014901 0.052501 0.284 0.777
L1.Steiermark -0.032076 0.066832 -0.480 0.631
L1.Tirol 0.159504 0.045991 3.468 0.001
L1.Vorarlberg 0.055965 0.042399 1.320 0.187
L1.Wien 0.219236 0.085887 2.553 0.011
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.239253 0.112501 2.127 0.033
L1.Burgenland 0.017330 0.055759 0.311 0.756
L1.Kärnten -0.072580 0.049035 -1.480 0.139
L1.Niederösterreich -0.082414 0.120217 -0.686 0.493
L1.Oberösterreich 0.027800 0.114994 0.242 0.809
L1.Salzburg 0.082478 0.063655 1.296 0.195
L1.Steiermark 0.330647 0.081030 4.081 0.000
L1.Tirol 0.461391 0.055762 8.274 0.000
L1.Vorarlberg 0.150605 0.051406 2.930 0.003
L1.Wien -0.150158 0.104133 -1.442 0.149
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185688 0.134181 1.384 0.166
L1.Burgenland 0.039206 0.066504 0.590 0.556
L1.Kärnten -0.075029 0.058485 -1.283 0.200
L1.Niederösterreich 0.129995 0.143383 0.907 0.365
L1.Oberösterreich 0.017058 0.137154 0.124 0.901
L1.Salzburg 0.201925 0.075921 2.660 0.008
L1.Steiermark 0.116439 0.096645 1.205 0.228
L1.Tirol 0.059561 0.066507 0.896 0.370
L1.Vorarlberg 0.101434 0.061312 1.654 0.098
L1.Wien 0.230383 0.124200 1.855 0.064
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.549375 0.073409 7.484 0.000
L1.Burgenland -0.018608 0.036384 -0.511 0.609
L1.Kärnten -0.018993 0.031996 -0.594 0.553
L1.Niederösterreich 0.080771 0.078443 1.030 0.303
L1.Oberösterreich 0.307714 0.075036 4.101 0.000
L1.Salzburg 0.017710 0.041536 0.426 0.670
L1.Steiermark -0.042616 0.052873 -0.806 0.420
L1.Tirol 0.080846 0.036385 2.222 0.026
L1.Vorarlberg 0.109671 0.033543 3.270 0.001
L1.Wien -0.060533 0.067949 -0.891 0.373
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.154847 0.095692 0.167164 0.222359 0.079356 0.085290 0.007847 0.159760
Kärnten 0.154847 1.000000 0.049832 0.206354 0.181282 -0.058440 0.168359 0.025964 0.302571
Niederösterreich 0.095692 0.049832 1.000000 0.239182 0.081424 0.327982 0.143494 0.024035 0.302012
Oberösterreich 0.167164 0.206354 0.239182 1.000000 0.300529 0.263484 0.089791 0.061122 0.132259
Salzburg 0.222359 0.181282 0.081424 0.300529 1.000000 0.156518 0.057182 0.088473 0.013152
Steiermark 0.079356 -0.058440 0.327982 0.263484 0.156518 1.000000 0.103713 0.095957 -0.098609
Tirol 0.085290 0.168359 0.143494 0.089791 0.057182 0.103713 1.000000 0.158607 0.144920
Vorarlberg 0.007847 0.025964 0.024035 0.061122 0.088473 0.095957 0.158607 1.000000 -0.007881
Wien 0.159760 0.302571 0.302012 0.132259 0.013152 -0.098609 0.144920 -0.007881 1.000000